package cn.com.dcsgo.springcloudstudy.order.controller;

import cn.com.dcsgo.springcloudstudy.commons.pojo.CommonResult;
import cn.com.dcsgo.springcloudstudy.commons.pojo.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * 消费者的业务调用接口
 * @author DCSGO
 * @version 1.0
 */
@RestController
@Slf4j
public class OrderController {
    //通过在eureka上注册过的微服务名称调用
    public static final String PAYMENT_URL="http://mcroservice-payment";

    @Autowired
    private RestTemplate restTemplate;
    //创建支付订单的接口
    @PostMapping("/consumer/payment/create")
    public CommonResult<Payment> create(@RequestBody Payment payment){
        return restTemplate.postForObject(PAYMENT_URL+"/payment/create",payment, CommonResult.class);
    }
    //通过id获取支付订单
    @GetMapping("/consumer/payment/get/{id}")
    public CommonResult<Payment> getPayment(@PathVariable("id") Long id) {
        return restTemplate.getForObject(PAYMENT_URL + "/payment/get/" + id, CommonResult.class);
    }
}
